# Author lihuanxing
# coding=utf-8
# @Time    : 2021/6/5 15:21
# @File    : file_size.py
# @Software: PyCharm
# @contact: lihuanxing
# @desc: 统计文件夹的大小

import os

# 累计文件大小
total_size = 0


def get_file_size(file_name):
    global total_size
    # 获取文件夹下的所有文件
    file_list = os.listdir(file_name)
    for file in file_list:
        file_path = os.path.join(file_name, file)
        # 判断是否是文件夹
        if os.path.isfile(file_path):
            size = os.path.getsize(file_path)
            total_size += size
        else:
            get_file_size(file_path)


if __name__ == '__main__':
    get_file_size(r'D:\download\拉勾数据分析')
    print(total_size)